package com.skywolf.chem.article.service.impl;

import com.skywolf.chem.article.entity.CollectionInfo;
import com.skywolf.chem.article.mapper.CollectionInfoMapper;
import com.skywolf.chem.article.pojo.CollectionQueryParam;
import com.skywolf.chem.article.service.ICollectionInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.skywolf.chem.common.sysconfig.pojo.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户收藏表 服务实现类
 * </p>
 *
 * @author 
 * @since 2020-06-09
 */
@Service
public class CollectionInfoServiceImpl extends ServiceImpl<CollectionInfoMapper, CollectionInfo> implements ICollectionInfoService {


    @Autowired
    CollectionInfoMapper collectionInfoMapper;

    @Override
    public PageVO<CollectionInfo> pageCollectionList(CollectionQueryParam queryParam) {
        Long startNum = queryParam.getPageSize()*(queryParam.getPageNum()-1);
        Long endNum = queryParam.getPageSize();
        Integer count = collectionInfoMapper.getCollectionPageCount(queryParam.getUid());
        List<CollectionInfo> list = collectionInfoMapper.getCollectionPageList(queryParam.getUid(),startNum,endNum);

        PageVO<CollectionInfo> pageVO = new PageVO<>();
        pageVO.setList(list);
        pageVO.setTotal(Long.valueOf(count));
        pageVO.setPageSize(queryParam.getPageSize());
        pageVO.setPageNum(queryParam.getPageNum());
        Long totalPage = (count/queryParam.getPageSize())+(count%queryParam.getPageSize()>0?1:0);
        if(totalPage.equals(0)){
            totalPage = queryParam.getPageNum();
        }
        pageVO.setPages(totalPage);
        return pageVO;
    }
}
